// 创建token
const jwt = require('jsonwebtoken')
const token = jwt.sign({userID: '234'}, 'atguigu', {expiresIn: 3})
console.log(token)

// 解码token
setTimeout(() => {
  jwt.verify(token, 'atguigu', (error, decode) => {
    if (error) {
      if (error.name === 'TokenExpiredError') {
        console.log('token过期了')
      } else {
        console.log('token非法')
      }
    } else {
      console.log('在有效期内：userId', decode.userId)
    }
  })
}, 4000)